$(function () {
    // body...
    loadHeader();  // 导入头部文件

    $.ajax({
        url: 'http://47.89.20.150/czlycms/index.php?m=Web&a=nav',
        type: 'GET',
        dataType: 'JSONP'
    })
    .done(function(data) {
        console.log("success");
        console.log(data);
        navfun(data.nav);
        navTwo(data.nav)
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
        NAVset();
        ButSearch();
    });



    function navfun(nav){
        var InOneNavList = $('#InOneNavList');
        var html = '';
        for (var i = 0; i < nav.length; i++) {
         var cn =  '<li><a href="'+nav[i].url+'">'+nav[i].title+'</a></li>' ;
         html+=cn;
     }
     InOneNavList.html(html);
     titleIndex = titleIndex-1;
     // if (titleIndex <= 0 ) {titleIndex = 0};
     if (titleIndex >= 0 && titleIndex < 7) {
         InOneNavList.find('li').eq(titleIndex).addClass('active');

         InOneNavList.find('li').hover(function(){
            console.log($(this).index());
            localStorage.indexName = $(this).index()+1;
            console.log(localStorage.indexName);


         },false)

     };

     console.log(titleIndex);


 }



 function navTwo(nav){
    var NavHDlst = $('#NavHDlst');
    var html = '';

    
   for (var j = 0; j < nav.length; j++) {
    var cn = '<li class="clearfloat">'+
                '<div class="LCn">'+
                    '<div class="head">'+nav[j].title+'</div>'+
                    '<div class="imgC"><img src="'+nav[j].image_url+'"></div>'+
                    '<p>'+nav[j].describe+'</p>'+
                '</div>'+
                '<ul class="naNoe">'+erjiNa(nav[j].children)+'</ul>'+'<ul class="naTwo">'+triNac(nav[j].children)+'</ul>'+
            ' </li>';
    html+=cn;
    // console.log(html)

    }



NavHDlst.html(html);

}


function erjiNa(nav){
    html = '';
    if (nav) {
        for (var k = 0; k < nav.length; k++) {
            var cn =  '<li class="'+IfOne(k)+' '+ifErjie(nav[k].children)+'"><a href="'+nav[k].url+'">'+expandEntities(nav[k].title)+'</a></li>';
            html+=cn;
        }
        return html;
    }else{
        return '';
    }
    
    function ifErjie(data) {
        if (data) {
            return 'erjie';
        }else{
            return ' ';

        }
    }

}

function triNac(nav){
    var html = '';
    if (nav) {
        for (var l = 0; l < nav.length; l++) {
            var cn = ' <li style="'+IfOneShow(l)+'"><ul class="naTwoN">'+ faiwuNav(nav[l].children) +'</ul></li>';
            html +=cn
        }
        return html;
    }else{
        return '';

    }
    
}

function faiwuNav(children){
    var html = '';
    if (children) {
        for (var i = 0; i < children.length; i++) {
            var cn = '<li><a href="'+children[i].url+'">'+expandEntities(children[i].title)+'</a></li>';
            html +=cn
        }
        return html;
    }else{
        return '';
    }

}




})




